//
//  AppDelegate.m
//  LoverGo
//
//  Created by yexiao on 14-9-7.
//  Copyright (c) 2014年 yexiao. All rights reserved.
//

#import "AppDelegate.h"
#import "DataCenter.h"
#import "RequestManager.h"
#import "MainViewController.h"

#import "UMSocial.h"
#import "UMFeedback.h"
#import "UMSocialQQHandler.h"
#import "GuideViewController.h"
#import "UMSocialWechatHandler.h"
#import "MobClick.h"
@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //创建主页面
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];
    
    [RequestManager getSingleton];//初始化网络连接单例
    [DataCenter getSingleton];
    
    //设置友盟Appkey
    [UMSocialData setAppKey:UmengAppkey];
    
    //设置微信AppId，url地址传nil，将默认使用友盟的网址
    [UMSocialWechatHandler setWXAppId:@"wx00bafff0e7728987" url:nil];
    //设置分享到QQ空间的应用Id，和分享url 链接
    [UMSocialQQHandler setQQWithAppId:@"1102302941" appKey:@"IWnv0xx5ZfDSZ20a" url:baseUrl];
    
    [UMFeedback setLogEnabled:YES];
    [UMFeedback checkWithAppkey:UmengAppkey];
    
    
    //如果你要支持不同的屏幕方向，需要这样设置，否则在iPhone只支持一个竖屏方向
    [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskAll];
    
    [MobClick startWithAppkey:@"541d3921fd98c5189a02a45e" reportPolicy:BATCH   channelId:@"Web"];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    [MobClick setAppVersion:version];
    [MobClick checkUpdate:@"有新版本" cancelButtonTitle:@"跳过" otherButtonTitles:@"进入下载"];
    
    NSUserDefaults *standard = [NSUserDefaults standardUserDefaults];
    BOOL isFirst =[[standard objectForKey:@"ISFIRST"] boolValue];
    if (isFirst == NO) {
        GuideViewController * gvc = [[GuideViewController alloc] init];
        [self.window setRootViewController:gvc];
    }else{
        MainViewController *mainViewController = [[MainViewController alloc]init];
        [self.window setRootViewController:mainViewController];
    }
    return YES;
}							
- (void)applicationWillResignActive:(UIApplication *)application
{
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [UMSocialSnsService  applicationDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    
}


@end
